/*
 * @Author: your name
 * @Date: 2019-10-14 09:27:30
 * @LastEditTime: 2019-10-26 10:11:21
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \vue_plugins\src\utils\option.js
 */
function getOption(value){
    const {
        random,
        PI,
        cos,
        sin
    } = Math;

    // 随机生成占比数据
    // const val = random() * 100;
    const val = value;


    // 圆心角的一半
    const angle = PI * val / 50 / 2;
    // 渐变起点
    const pointStart = [
        0.5 - 0.5 * cos(angle) * sin(angle),
        0.5 + 0.5 * cos(angle) * cos(angle)
    ];
    // 渐变终点
    const pointEnd = [
        0.5 - 0.5 * sin(angle),
        0.5 + 0.5 * cos(angle)
    ];


    const option = {
        title: {//图标标题，暂时不要
            text: '环形进度条',
            left: 'center',
            bottom:0,
            textStyle: {
                align: 'center',
                fontSize: 14,
                color: '#333',
                fontWeight: 'normal'
            }
        },
        series: [{
            name: '占比',
            type: 'pie',
            startAngle: -270, // 环图起始位置：正下发
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: true,
                    position: 'center',
                    formatter: ({
                        data
                    }) => `${data.value.toFixed(2)}%`
                },
                emphasis: {
                    show: true
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data: [{
                name: '完成率',
                value: val,
                label: {
                    normal: {
                        fontSize: 12,
                        color: '#585F6E',
                        fontWeight: 'bolder'
                    }
                },
                itemStyle: {
                    normal: {
                        color: {
                            type: 'linear',
                            x: pointStart[0],
                            y: pointStart[1],
                            x2: pointEnd[0],
                            y2: pointEnd[1],
                            colorStops: [
                                // !! 在此添加渐变过程色 !!
                                {
                                    offset: 0,
                                    color: '#24BCF9'
                                },
                                {
                                    offset: 1,
                                    color: '#1ADAE9'
                                }
                            ]
                        },
                        shadowColor: 'rgba(34,192,245,0.8)',
                        shadowBlur: 10
                    }
                }
            }, {
                name: '未完成率',
                value: 100 - val,
                label: {
                    normal: {
                        show: false,
                        fontSize: 0
                    }
                },
                itemStyle: {
                    normal: {
                        color: '#f0f0f0'
                    },
                    emphasis: {
                        color: '#f0f0f0'
                    }
                },
                hoverAnimation: false
            }]
        }]
    }

    return option;
}
export {getOption}